<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-9-27
 * Time: 21:08
 */



try{
    //已经完成了连接数据库
    $pdo = new PDO("mysql:dbname=bk_ui;host=127.0.0.1","root","");
//    echo "连接成功";//没有错误,代表成功
    //连接后马上改变编码
    $pdo->exec("SET NAMES 'utf8';");

//    $sql = "select * from tb_comment c left join tb_user u ON c.user_id = u.id;";

$sql = "SELECT * FROM  `bk_user`;";
    //查到pdo对象结果集
    $res = $pdo->query($sql);
    //一行一行的循环
    echo "<table border='1'>";

    echo "<tr>
            <th>编号</th>
            <th>名字</th>
            <th>电话号码</th>
            <th>日记</th>
            <th>时间</th>
            <th>操作栏</th>
          </tr>";
    foreach ($res as $row){
//        var_dump($row);
        echo "<tr>";
        //如果只要单个字段
        echo "<td>{$row['id']}</td>";
        echo "<td>{$row['name']}</td>";
//        echo "<td>{$row['pass']}</td>";
        echo "<td>{$row['tel']}</td>";
        echo "<td>{$row['rj']}</td>";
        echo "<td>{$row['time']}</td>";

        echo "<td>
    <a href='modify.php?id={$row['id']}&text={$row['rj']}'>修改日记</a>
    <a href='Delete.php?id={$row['id']}'>删除</a></td>";
        echo "</tr>";
    }
    echo "</table>";


}catch (Exception $e){
    echo "连接失败".$e->getMessage();
}

